package com.medusa.aps.business.modules.basic.controller;


import com.medusa.aps.business.model.pagination.Page;
import com.medusa.aps.business.modules.basic.model.WorkingPeriodModel;
import com.medusa.aps.business.modules.basic.model.input.WorkingPeriodPagePram;
import com.medusa.aps.business.modules.basic.mp.entity.WorkingPeriod;
import com.medusa.aps.business.modules.basic.mp.service.WorkingPeriodService;
import com.medusa.aps.business.common.model.resp.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 工作时段控制层
 *
 * @author yuxh
 * @since 2023-08-14 17:37:53
 */
@Validated
@Tag(name = "工作时段控制层")
@RestController
@RequestMapping("/workingPeriod")
public class WorkingPeriodController {
    /**
     * 服务对象
     */
    @Resource
    private WorkingPeriodService workingPeriodService;

    /**
     * 分页查询所有数据
     *
     * @param queryPage 分页查询参数
     * @return 所有数据
     */
    @GetMapping
    @Operation(description = "分页查询所有数据", method = "GET", summary = "分页查询所有数据")
    public Result<Page<WorkingPeriodModel>> periodPage(WorkingPeriodPagePram queryPage) {
        return Result.ok(
                this.workingPeriodService.periodPage(queryPage)
        );
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(description = "通过主键查询单条数据", method = "GET", summary = "通过主键查询单条数据")
    @GetMapping("/detail")
    public Result<WorkingPeriod> selectOne(@RequestParam Integer id) {
        return Result.ok(this.workingPeriodService.getById(id));
    }

    /**
     * 新增或修改数据
     *
     * @param periodModels 工作时段参数
     * @return 新增结果
     */
    @Operation(description = "新增工作时段", method = "POST", summary = "新增工作时段")
    @PostMapping(value = "/save")
    public Result<Void> saveWorkingPeriod(@RequestBody @Valid @Size(min = 1, message = "至少处理一条数据") List<WorkingPeriodModel> periodModels) {
        this.workingPeriodService.saveWorkingPeriod(periodModels);
        return Result.ok();
    }

    /**
     * 新增或修改数据
     *
     * @param periodModels 工作时段参数
     * @return 新增结果
     */
    @Operation(description = "修改工作时段", method = "POST", summary = "修改工作时段")
    @PutMapping(value = "/update")
    public Result<Void> updateBatch(@RequestBody @Valid @Size(min = 1, message = "至少处理一条数据") List<WorkingPeriodModel> periodModels) {
        this.workingPeriodService.updateWorkingPeriod(periodModels);
        return Result.ok();
    }

    /**
     * 批量删除数据
     *
     * @param periodIds 主键结合
     * @return void
     */
    @Operation(description = "批量删除数据", method = "DELETE", summary = "批量删除数据")
    @DeleteMapping("/delete")
    public Result<Void> deleteBatch(@RequestBody @NotNull @Size(min = 1) Set<Integer> periodIds) {
        this.workingPeriodService.deleteBatch(periodIds);
        return Result.ok();
    }
}

